<template>
  <div>
    <div :style="{ margin: '20px 0', textAlign: 'right' }">
      <el-button v-if="type == 'create'" @click="cancle">取 消</el-button>
      <el-button v-if="type != 'create'" type="primary" @click="exit">关 闭</el-button>
      <el-button
        v-if="type == 'close'"
        type="primary"
        :loading="loginBtnState"
        :disabled="isClosed || !closeing"
        @click="closeComplaint"
      >结 案</el-button>
      <el-button
        v-if="type != 'readDetail'"
        type="primary"
        :loading="loginBtnState"
        :disabled="isClosed || closeing"
        @click="commit"
      >保 存</el-button>
      <el-button
        v-if="type != 'readDetail'"
        type="primary"
        :loading="loginBtnState"
        :disabled="isClosed || closeing"
        @click="exhale('0')"
      >智能外呼</el-button>
      <el-button
        v-if="type != 'readDetail'"
        type="primary"
        :loading="loginBtnState"
        :disabled="isClosed || closeing"
        @click="exhale('00')"
      >加0外呼</el-button>
      <el-button
        v-if="type != 'readDetail' && type != 'close'"
        type="primary"
        :loading="loginBtnState"
        :disabled="isClosed || closeing"
        @click="report"
      >上 报</el-button>
    </div>
    <div class="box">
      投诉信息
      <hr class="hr1" />
      <FormPanel
        ref="formPanel1"
        :list="formList1"
        formType="add"
        :cols="4"
        labelWidth="100"
        :scrollContainer="scrollWrap"
        :isSubmitBtn="false"
        @formChange="formChangeHandle1"
      />
    </div>

    <div class="box">
      投诉调查
      <hr class="hr1" />
      <FormPanel
        ref="formPanel4"
        :list="formList4"
        formType="add"
        :cols="2"
        labelWidth="100%"
        :scrollContainer="scrollWrap"
        :isSubmitBtn="false"
        @formChange="formChangeHandle4"
      />
    </div>

    <div class="box">
      状态登记
      <hr class="hr1" />
      <FormPanel
        ref="formPanel5"
        :list="formList5"
        formType="add"
        :cols="4"
        labelWidth="100"
        :scrollContainer="scrollWrap"
        :isSubmitBtn="false"
        @formChange="formChangeHandle5"
      />
    </div>

    <div v-if="type != 'create'" class="box">
      处理明细
      <el-button
        v-if="type != 'readDetail' && !isClosed"
        style="margin-left:20px"
        size="small"
        :scrollContainer="scrollWrap"
        type="primary"
        icon="el-icon-plus"
        @click="addComplaintDetail"
      >新增</el-button>
      <hr class="hr1" />
      <FilterTable
        ref="table1"
        :columns="columns1"
        :height="'auto'"
        :isSelectColumn="false"
        :isToperInfo="false"
        :isColumnFilter="false"
        :dataSource="complaintDetailList"
        :onCellChange="onCellChange"
        columnsRef="khtsKhtsmxClxxTable"
        :onColumnsChange="columns => (this.columns = columns)"
      ></FilterTable>
    </div>

    <div class="box">
      车辆信息
      <hr class="hr1" />
      <FormPanel
        ref="formPanel3"
        :list="formList3"
        formType="add"
        :cols="4"
        labelWidth="100"
        :scrollContainer="scrollWrap"
        :isSubmitBtn="false"
        @formChange="formChangeHandle3"
      />
    </div>

    <div class="box">
      工单信息
      <hr class="hr1" />
      <FormPanel
        ref="formPanel2"
        :list="formList2"
        formType="add"
        :cols="3"
        labelWidth="100"
        :scrollContainer="scrollWrap"
        :isSubmitBtn="false"
        @formChange="formChangeHandle2"
      />
    </div>
    <Drawer
      :visible.sync="showChooseRO"
      title="工单号"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <ChooseRO :vinData="vinData" @req="reqChooseRO" @cancle="closeDia" />
    </Drawer>

    <Drawer
      :visible.sync="showChooseVehicle"
      title="车辆信息选择"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <ChooseVehicle @req="reqChooseVehicle" @cancle="closeDia" />
    </Drawer>
  </div>
</template>
<script>
import { mapActions, mapState } from 'vuex';
import dictCode from '@/utils/dictCode';
import * as types from '@/api/customerRepair/customerComplaint/customerComplaintReception/types.js';
import { dictionary } from '@/utils/dictMixin';
import { getUser } from '@/assets/js/auth';
import { getOwnerCode } from '@/assets/js/auth';
import { confirmAction, isFormEmpty } from '@/utils';
import { getDealerEmp } from '@/api/vehicleSales/interchange/vehicleChargeback';
import ChooseRO from '../components/chooseRO';
import ChooseVehicle from '../components/chooseVehicle';
import {
  addComplaint,
  sendAccComplaint,
  getCompalaintById,
  delComplaintDetailById,
  closeComplaintById,
  searchDealerOrg,
  getDealerUser,
  findAllRepairType,
  searchRepairOrder,
  searchVehicle
} from '@/api/customerRepair/customerComplaint/customerComplaintReception';
import { getModelList } from '@/api/customerRepair/customerComplaint/customerComplaintMng';
import { saveComplaintAndDetail } from '@/api/customerRepair/customerComplaint/customerComplaintAnalysis';
import { searchRoleByCode } from '@/api/common/empSelect/index';
import { phoneAndMobel, VIN, isValidateDouble, ownerLicensePlate } from '@/utils/validate';
import moment from 'moment';

export default {
  name: 'NemoCustomerComplaintReceptionEdit',
  components: {
    ChooseRO,
    ChooseVehicle
  },
  mixins: [dictionary],
  props: {
    editComplaintId: Number,
    type: {
      type: String,
      default: 'create'
    },
    flag: {
      type: String,
      default: '1' // 1 投诉模块，2 CTI弹屏 ，3 关怀模块
    },
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    this.scrollWrap = null;
    this.BaseTable = null;
    // nowDate: null;
    return {
      formList1: this.createFormList1(), // 投诉信息表单
      formList2: this.createFormList2(), // 工单信息表单
      formList3: this.createFormList3(), // 车辆信息表单
      formList4: this.createFormList4(), // 投诉调查表单
      formList5: this.createFormList5(), // 状态登记表单
      form1Over: false, // 投诉信息表单验证成功
      form2Over: false, // 工单信息表单验证成功
      form3Over: false, // 车辆信息表单验证成功
      form4Over: false, // 投诉调查表单验证成功
      form5Over: false, // 状态登记表单验证成功
      showChooseRO: false, // 是否显示选择工单
      showChooseVehicle: false, // 是否显示选择车辆信息

      customerComplaint: {
        complaintId: ''
      }, // 最终保存客户投诉对象
      columns1: this.createTableColumns1(), // 跟进信息表格列
      complaintDetailList: [], // 跟进信息表格数据

      closeing: false, // 判断是否可以结案
      isClosed: false, // 是否结案成功
      dealerOrgId: null,
      emplList: [],
      compliantTypeList: [
        { text: '服务类', value: 82151001 },
        { text: '技术类', value: 82151002 },
        { text: '销售类', value: 82151003 },
        { text: '金融类', value: 82151004 },
        { text: '备件类', value: 82151005 }
      ],
      compliantKindList: [
        { text: '投诉单', value: 82131001 },
        { text: '建议单', value: 82131003 },
        { text: '咨询单', value: 82131004 },
        { text: '表扬单', value: 82131005 }
      ],
      complaintMainTypeList: [],
      complaintSubTypeList: [],
      vinData: null,
      /* 呼叫中心所需字段----begin */
      afterVal: '',
      HFDH: '',
      ctiUrl: null,
      callid: null
      /* 呼叫中心所需字段 ----end*/
    };
  },
  computed: {
    ...mapState('app', ['btnLoading']),
    loginBtnState() {
      return this.btnLoading[types.SAVE];
    }
  },
  created() {},
  mounted() {
    this.scrollWrap = document.querySelector('.scroll-wrapper');
    this.getEmp();
    this.getModelList();
    this.after();
    this.formList1.find(x => x.fieldName == 'complaintType').itemList = this.compliantTypeList;
    if (this.editComplaintId) {
      this.getCompalaint();
    }
    if (this.type === 'create') {
      const nowDate = this.getNowDate();
      this.formList1.find(item => item.fieldName === 'complaintDate').initialValue = nowDate; // 投诉时间
      this.formList1.find(item => item.fieldName === 'complaintKind').itemList = this.compliantKindList; // 单据类型
    } else {
      this.formList1.find(item => item.fieldName === 'complaintKind').itemList = this.createDictList('8213'); // 单据类型
      this.formList1.find(item => item.fieldName === 'complaintName').rules = null;
      this.formList1.find(item => item.fieldName === 'complaintMobile').rules = null;
      this.formList1.find(item => item.fieldName === 'complaintType').rules = null;
      this.formList1.find(item => item.fieldName === 'complaintKind').rules = null;
      this.formList1.find(item => item.fieldName === 'complaintMainType').rules = null;
      this.formList1.find(item => item.fieldName === 'complaintSubType').rules = null;
      this.formList1.find(item => item.fieldName === 'handleStatus').rules = null;
      if (this.type === 'readDetail') {
        /* 查看明细页面去除必填项 */
        this.formList4.find(item => item.fieldName === 'complaintSummary').rules = null;
        this.formList4.find(item => item.fieldName === 'complaintReason').rules = null;
        this.formList4.find(item => item.fieldName === 'surveyContent').rules = null;
        this.formList4.find(item => item.fieldName === 'resolvent').rules = null;
        this.formList4.find(item => item.fieldName === 'asdtxt').rules = null;
        /* 查看明细页面去除必填项 */
        this.formList5.find(item => item.fieldName === 'priority').rules = null;
        this.formList5.find(item => item.fieldName === 'complaintOrigin').rules = null;
        this.formList5.find(item => item.fieldName === 'result').rules = null;
      }
    }
    this.setDefaultDic();
    this.getDealerOrg();
    if (this.flag == '2') {
      // CTI弹屏
      this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = this.rowData.phone; // 投诉电话号
      this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = this.rowData.phone; // 投诉电话号
    } else if (this.flag === '15721001' || this.flag === '15721002' || this.flag === '15721003' || this.flag === '15721004' || this.flag === '15721005' || this.flag === '15721006') {
      this.getRoInfo(this.rowData);
    }
  },
  methods: {
    // 投诉信息表单
    createFormList1() {
      return [
        {
          type: 'INPUT',
          label: '投诉编号',
          fieldName: 'complaintNo',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '投诉人姓名',
          fieldName: 'complaintName',
          disabled: !(this.type == 'create'),
          rules: [{ required: true, message: '请填写投诉人姓名', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '投诉人性别',
          fieldName: 'complaintGender',
          disabled: !(this.type == 'create'),
          itemList: this.createDictList('8012'),
          rules: [{ required: false, message: '请选择投诉人性别', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '投诉人电话',
          fieldName: 'complaintPhone',
          disabled: !(this.type == 'create')
        },
        {
          type: 'INPUT',
          label: '投诉人手机',
          fieldName: 'complaintMobile',
          disabled: !(this.type == 'create'),
          rules: [{ required: true, validator: this.checkPhone, trigger: 'blur', message: '请输入联系人手机' }]
        },
        {
          type: 'SELECT',
          label: '单据类型',
          fieldName: 'complaintKind',
          disabled: !(this.type == 'create'),
          itemList: [],
          initialValue: 82131001,
          // itemList: this.createDictList('8213'),
          change: val => {
            this.changeComplaintRules(val);
          },
          initialValue: null,
          rules: [{ required: true, message: '请选择单据类型', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '投诉类别',
          fieldName: 'complaintType',
          disabled: !(this.type == 'create'),
          itemList: [],
          initialValue: null,
          rules: [{ required: true, message: '请选择投诉类型', trigger: 'change' }],
          change: val => {
            this.changeComplaintMainType(val);
          }
        },
        {
          type: 'SELECT',
          label: '原因描述分类',
          fieldName: 'complaintMainType',
          disabled: !(this.type == 'create'),
          itemList: [],
          initialValue: null,
          rules: [{ required: true, message: '请选择原因描述分类', trigger: 'change' }],
          change: val => {
            this.changeComplaintSubType(val);
          }
        },
        {
          type: 'SELECT',
          label: '原因描述',
          fieldName: 'complaintSubType',
          disabled: !(this.type == 'create'),
          itemList: [],
          initialValue: null,
          rules: [{ required: true, message: '请选择原因描述', trigger: 'change' }]
        },
        {
          type: 'DATE_TIME',
          label: '投诉日期',
          maxDateTime: moment(),
          fieldName: 'complaintDate',
          disabled: true,
          initialValue: this.getNowDate()
        },
        {
          type: 'SELECT',
          label: '投诉处理状态',
          fieldName: 'handleStatus',
          disabled: this.type == 'create' || this.type == 'readDetail',
          initialValue: 80481001,
          itemList: this.createDictList('8048'),
          rules: [{ required: true, message: '请选择处理状态', trigger: 'change' }],
          change: val => {
            this.changePrincipalRequird(val);
          }
        },

        {
          type: 'INPUT',
          label: '接待员',
          fieldName: 'receptionst',
          disabled: true,
          initialValue: getUser()
        },
        {
          type: 'INPUT',
          label: '厂端下发类型',
          disabled: true,
          fieldName: 'compquestdesc'
        },
        {
          type: 'INPUT',
          label: '投诉单位',
          disabled: !(this.type == 'create'),
          fieldName: 'complaintCorp'
        }
      ];
    },
    // 工单信息表单
    createFormList2() {
      return [
        {
          type: 'INPUT',
          label: '工单号',
          fieldName: 'roNo',
          disabled: !(this.type == 'create'),
          readonly: true,
          unitRender: props => {
            return (
              <div>
                <i slot="suffix" style="line-height: 30px" class="el-input__icon el-icon-circle-plus" onClick={() => this.openChooseRO()}></i>
                <i slot="suffix" style="line-height: 30px" class="el-input__icon el-icon-error" onClick={() => this.delRepairOrder()}></i>
              </div>
            );
          }
        },
        {
          type: 'DATE',
          label: '开单时间',
          disabled: true,
          // style:{width:'200px'},
          lableWidth: '50px',
          fieldName: 'roCreateDate'
        },
        {
          type: 'SELECT',
          label: '维修类型',
          disabled: true,
          fieldName: 'repairTypeCode',
          request: {
            fetchApi: findAllRepairType,
            valueKey: 'REPAIR_TYPE_CODE',
            textKey: 'REPAIR_TYPE_NAME'
          }
        },
        {
          type: 'SELECT',
          label: '服务顾问',
          disabled: true,
          fieldName: 'serviceAdvisor',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '送修人',
          disabled: true,
          fieldName: 'deliverer'
        },
        {
          type: 'INPUT',
          label: '送修人手机',
          disabled: true,
          fieldName: 'delivererMobile'
        },
        {
          type: 'INPUT',
          label: '送修人电话',
          disabled: true,
          fieldName: 'delivererPhone'
        },
        {
          type: 'SELECT',
          label: '责任技师',
          disabled: true,
          fieldName: 'techician',
          itemList: []
        }
      ];
    },
    // 车辆信息表单
    createFormList3() {
      return [
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license',
          disabled: !(this.type == 'create'),
          readonly: false,
          style: { width: '200px' },
          // rules: [{ required: false, validator: ownerLicensePlate, trigger: 'blur', message: '请输入车牌号' }],
          unitRender: props => {
            return (
              <div>
                <i slot="suffix" style="line-height: 30px" class="el-input__icon el-icon-circle-plus" onClick={() => this.openChooseVehicle()}></i>
                <i slot="suffix" style="line-height: 30px" class="el-input__icon el-icon-error" onClick={() => this.delVehicle()}></i>
              </div>
            );
          }
        },
        {
          type: 'INPUT',
          label: 'VIN',
          disabled: !(this.type == 'create'),
          rules: [{ required: false, validator: VIN, trigger: 'blur', message: '请输入正确VIN' }],
          fieldName: 'vin'
        },
        {
          type: 'INPUT',
          label: '发动机号',
          disabled: !(this.type == 'create'),
          fieldName: 'engineNo'
        },
        {
          type: 'SELECT',
          label: '车型',
          fieldName: 'vehicleModel',
          disabled: this.type == 'detail',
          itemList: [],
          initialValue: null,
          rules: [{ required: this.type == 'create', message: '请选择车型', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '车主',
          disabled: !(this.type == 'create'),
          fieldName: 'ownerName'
        },
        {
          type: 'SELECT',
          label: '车主性质',
          fieldName: 'ownerProperTy',
          disabled: !(this.type == 'create'),
          itemList: this.createDictList('8011')
        },
        {
          type: 'INPUT',
          label: '行驶里程',
          disabled: !(this.type == 'create'),
          fieldName: 'inMileage'
        },
        {
          type: 'DATE',
          label: '购车日期',
          disabled: !(this.type == 'create'),
          maxDateTime: moment(),
          fieldName: 'buyCarDate',
          rules: [{ required: false, message: '请选择投诉时间', trigger: 'change' }],
          change: val => {
            this.formList1.find(x => x.fieldName === 'buyCarDate').maxDateTime = val;
          }
        },
        {
          type: 'INPUT',
          label: '车主地址',
          disabled: !(this.type == 'create'),
          selfCols: 2,
          fieldName: 'linkAddress'
        }
      ];
    },
    // 投诉调查表单
    createFormList4() {
      return [
        {
          type: 'TEXT_AREA',
          label: '投诉摘要',
          fieldName: 'complaintSummary',
          disabled: this.type === 'readDetail',
          // readonly:false,
          maxlength: 5000,
          rules: [{ required: true, message: '请填写投诉内容', trigger: 'blur' }]
        },
        {
          type: 'TEXT_AREA',
          label: '投诉原因',
          fieldName: 'complaintReason',
          // readonly:false,
          disabled: this.type === 'readDetail',
          maxlength: 5000
        },
        {
          type: 'TEXT_AREA',
          label: '备注信息',
          fieldName: 'surveyContent',
          // readonly:false,
          disabled: this.type === 'readDetail',
          maxlength: 5000
        },
        {
          type: 'TEXT_AREA',
          label: '解决方案',
          fieldName: 'resolvent',
          // readonly:false,
          disabled: this.type === 'readDetail',
          maxlength: 5000
        },
        {
          type: 'TEXT_AREA',
          label: '总部意见',
          fieldName: 'asdtxt',
          disabled: true,
          maxlength: 500
        }
      ];
    },
    // 状态表单
    createFormList5() {
      return [
        {
          type: 'SELECT',
          label: '处理人',
          filterable: true,
          fieldName: 'principal',
          disabled: this.type == 'readDetail',
          initialValue: getUser(),
          itemList: [],
          change: val => {
            this.changeCloseStatus();
          }
        },
        {
          type: 'SELECT',
          label: '投诉级别',
          fieldName: 'priority',
          itemList: this.createDictList('8032'),
          disabled: this.type == 'readDetail',
          rules: [{ required: true, message: '请选择投诉级别', trigger: 'change' }],
          change: val => {
            console.log('投诉级别change事件==============');
            console.log(val);
            if (val === 80321002 || val === 80321002 || val === 80321003 || val === 80321004) {
              this.formList5.find(x => x.fieldName === 'userDemand').rules = [{ required: true, message: '请输入客户要求', trigger: 'blur' }];
            } else {
              this.formList5.find(x => x.fieldName === 'userDemand').rules = [];
            }
            this.formList5 = [...this.formList5];
            console.log(this.formList5.find(x => x.fieldName === 'userDemand').rules);
            this.changeCloseStatus();
          }
        },
        {
          type: 'SELECT',
          label: '投诉来源',
          fieldName: 'complaintOrigin',
          itemList: this.createDictList('8009'),
          disabled: this.type == 'readDetail',
          rules: [{ required: true, message: '投诉来源', trigger: 'change' }],
          change: val => {
            this.changeCloseStatus();
          }
        },
        // {
        //   type: 'SELECT',
        //   label: '被投诉部门',
        //   fieldName: 'department',
        //   disabled: this.type == 'readDetail',
        //   itemList: [],
        //   change: val => {
        //     this.getDealerEmp(val);
        //   }
        // },
        {
          type: 'SELECT',
          label: '被投诉员工',
          filterable: true,
          disabled: this.type == 'readDetail',
          fieldName: 'beComplaintEmp',
          itemList: []
        },
        {
          type: 'SELECT',
          label: '投诉结果',
          fieldName: 'result',
          itemList: this.createDictList('8205'),
          disabled: this.type == 'readDetail',
          rules: [{ required: true, message: '投诉结果', trigger: 'change' }],
          change: val => {
            this.changeCloseStatus();
          }
        },
        {
          type: 'SELECT',
          label: '用户初始情绪',
          fieldName: 'attitude1',
          itemList: [
            { text: '非常满意', value: '1' },
            { text: '很满意', value: '2' },
            { text: '一般', value: '3' },
            { text: '不满意', value: '4' },
            { text: '非常不满意', value: '5' }
          ],
          disabled: this.type == 'detail',
          rules: [{ required: true, message: '请选择用户初始化情绪', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '重新处理次数',
          disabled: true,
          offsetLeftCols: 1,
          hidden: this.type == 'create',
          fieldName: 'repeatDealTimes'
        },
        {
          type: 'SELECT',
          label: '结案状态',
          hidden: !(this.type == 'close'),
          fieldName: 'closeStatus',
          disabled: true,
          itemList: this.createDictList('8042')
        },
        {
          type: 'SELECT',
          label: '回访结果',
          hidden: !(this.type == 'close'),
          fieldName: 'complaintResult',
          itemList: this.createDictList('8043'),
          change: val => {
            this.changeCloseStatus();
          }
        },
        {
          type: 'CHECKBOX',
          label: '置为重新处理',
          offsetLeftCols: 1,
          hidden: !(this.type == 'close'),
          fieldName: 'isRepeat',
          change: val => {
            this.changeCloseStatus();
          }
        },
        {
          type: 'TEXT_AREA',
          label: '客户要求',
          fieldName: 'userDemand',
          selfCols: 2
        }
      ];
    },
    // 跟进信息表格
    createTableColumns1() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          fixed: 'left',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          hidden: this.type == 'readDetail',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.delComplaintDetail(props.row)}>
                  删除
                </el-button>
              </div>
            );
          }
        },
        {
          title: '处理时间',
          dataIndex: 'dealDate',
          disabled: true,
          showOverflowTooltip: true
        },
        {
          title: '处理人',
          dataIndex: 'dealer',
          editable: true,
          filterable: true,
          editType: 'select',
          editRequired: true,
          editItems: [],
          // initialValue:getuser(),
          disabled: this.type == 'readDetail'
        },
        {
          title: '处理结果描述',
          dataIndex: 'dealResult',
          editable: true,
          editType: 'input',
          editRequired: true,
          disabled: this.type == 'readDetail'
        },
        {
          title: '备注',
          dataIndex: 'remark',
          editable: true,
          editType: 'input',
          disabled: this.type == 'readDetail'
        }
      ];
    },
    // 处理明细表格改变时
    onCellChange() {
      this.changeCloseStatus();
    },
    // 当前选中已处理时，处理人改成必填
    changePrincipalRequird(val) {
      if (val == 80481002) {
        this.formList5.find(item => item.fieldName === 'principal').rules = [{ required: true, message: '请填写处理人', trigger: 'blur' }];
      } else {
        this.formList5.find(item => item.fieldName === 'principal').rules = [];
      }
      this.formList5 = [...this.formList5];
    },
    // 内容改变时，置灰结案按钮，置亮保存按钮
    changeCloseStatus() {
      this.closeing = false;
    },
    // 新增跟进明细
    addComplaintDetail() {
      let newDetail = {
        complaintNo: this.customerComplaint.complaintNo,
        dealDate: this.getNowDate(), // 处理时间
        dealer: getUser(), // 处理人
        dealResult: '', // 处理结果
        remark: '' // 备注
      };
      this.complaintDetailList.push(newDetail);
      this.complaintDetailList = [...this.complaintDetailList];
      this.changeCloseStatus();
    },
    // 删除跟进明细
    delComplaintDetail(row) {
      this.$confirm('是否确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // 有complaintDetailId，直接真删，再从complaintDetailList中移除
          if (row.complaintDetailId) {
            delComplaintDetailById(row.complaintDetailId).then(res => {
              if (res.resultCode == 200) {
                this.complaintDetailList.splice(row.$index, 1);
              }
            });
          } else {
            // 没有complaintDetailId，直接从complaintDetailList中移除
            this.complaintDetailList.splice(row.$index, 1);
          }
          this.complaintDetailList = [...this.complaintDetailList];
          this.changeCloseStatus();
        })
        .catch(() => {});
    },
    // 获取当前时间
    getNowDate() {
      let date = new Date();
      let Y = date.getFullYear() + '-';
      let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
      let D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() + ' ';
      let h = date.getHours() + ':';
      let m = date.getMinutes() + ':';
      let s = date.getSeconds();
      return Y + M + D + ' ' + h + m + s;
    },

    // 打开选择工单弹框
    openChooseRO() {
      this.vinData = {
        vin: this.formList3.find(item => item.fieldName === 'vin').initialValue
      };
      this.showChooseRO = true;
    },
    // 选择工单
    reqChooseRO(chooseRepairOrder) {
      /* 将车主信息默认带入到投诉人字段中 */
      this.formList1.find(item => item.fieldName === 'complaintName').initialValue = chooseRepairOrder.DELIVERER; // 投诉人
      this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = chooseRepairOrder.DELIVERER_MOBILE; // 投诉人手机
      this.formList1.find(item => item.fieldName === 'complaintPhone').initialValue = chooseRepairOrder.PHONE; // 投诉人电话
      this.formList1.find(item => item.fieldName === 'complaintGender').initialValue = chooseRepairOrder.GENDER; // 投诉人性别

      this.formList2.find(item => item.fieldName === 'roNo').initialValue = chooseRepairOrder.RO_NO; // 工单号
      this.formList2.find(item => item.fieldName === 'roCreateDate').initialValue = chooseRepairOrder.RO_CREATE_DATE; // 开单时间
      this.formList2.find(item => item.fieldName === 'repairTypeCode').initialValue = chooseRepairOrder.REPAIR_TYPE_CODE; // 维修类型代码
      this.formList2.find(item => item.fieldName === 'serviceAdvisor').initialValue = chooseRepairOrder.sa; // 服务顾问
      this.formList2.find(item => item.fieldName === 'deliverer').initialValue = chooseRepairOrder.DELIVERER; // 送修人
      this.formList2.find(item => item.fieldName === 'delivererPhone').initialValue = chooseRepairOrder.DELIVERER_PHONE; // 送修人电话
      this.formList2.find(item => item.fieldName === 'delivererMobile').initialValue = chooseRepairOrder.DELIVERER_MOBILE; // 送修人手机
      this.formList2.find(item => item.fieldName === 'techician').initialValue = chooseRepairOrder.ct; // 责任技师
      this.formList3.find(item => item.fieldName === 'license').initialValue = chooseRepairOrder.LICENSE; // 车牌号
      this.formList3.find(item => item.fieldName === 'license').readonly = true;
      this.formList3.find(item => item.fieldName === 'vin').initialValue = chooseRepairOrder.VIN; // VIN
      this.formList3.find(item => item.fieldName === 'vin').disabled = true;
      this.formList3.find(item => item.fieldName === 'ownerName').initialValue = chooseRepairOrder.OWNER_NAME; // 车主
      this.formList3.find(item => item.fieldName === 'ownerName').disabled = true;
      this.formList3.find(item => item.fieldName === 'ownerProperTy').initialValue = chooseRepairOrder.OWNER_PROPERTY; // 车主性质
      this.formList3.find(item => item.fieldName === 'ownerProperTy').disabled = true;
      this.formList3.find(item => item.fieldName === 'inMileage').initialValue = chooseRepairOrder.MILEAGE; // 行驶里程
      this.formList3.find(item => item.fieldName === 'inMileage').disabled = true;
      this.formList3.find(item => item.fieldName === 'buyCarDate').initialValue = chooseRepairOrder.SALES_DATE; // 购车日期
      this.formList3.find(item => item.fieldName === 'buyCarDate').disabled = true;
      this.formList3.find(item => item.fieldName === 'linkAddress').initialValue = chooseRepairOrder.ADDRESS; // 车主地址
      this.formList3.find(item => item.fieldName === 'linkAddress').disabled = true;
      this.formList3.find(item => item.fieldName === 'engineNo').initialValue = chooseRepairOrder.ENGINE_NO; // 车主地址
      this.formList3.find(item => item.fieldName === 'engineNo').disabled = true;
      this.showChooseRO = false;
    },
    // 删除工单
    delRepairOrder() {
      this.$refs.formPanel2.RESET_FORM();
      this.delVehicle();
    },
    // 打开选择车辆弹框
    openChooseVehicle() {
      this.showChooseVehicle = true;
    },
    // 选择车辆
    reqChooseVehicle(chooseVehicle) {
      /* 将车主信息默认带入到投诉人字段中 */
      this.formList1.find(item => item.fieldName === 'complaintName').initialValue = chooseVehicle.OWNER_NAME; // 投诉人
      this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = chooseVehicle.MOBILE; // 投诉人手机
      this.formList1.find(item => item.fieldName === 'complaintPhone').initialValue = chooseVehicle.PHONE; // 投诉人电话
      this.formList1.find(item => item.fieldName === 'complaintGender').initialValue = chooseVehicle.GENDER; // 投诉人性别

      this.formList3.find(item => item.fieldName === 'license').initialValue = chooseVehicle.LICENSE; // 车牌号
      this.formList3.find(item => item.fieldName === 'license').readonly = true;
      this.formList3.find(item => item.fieldName === 'vin').initialValue = chooseVehicle.VIN; // VIN
      this.formList3.find(item => item.fieldName === 'vin').disabled = true;
      this.formList3.find(item => item.fieldName === 'vin').rules = [];
      this.formList3.find(item => item.fieldName === 'ownerName').initialValue = chooseVehicle.OWNER_NAME; // 车主
      this.formList3.find(item => item.fieldName === 'ownerName').disabled = true;
      this.formList3.find(item => item.fieldName === 'ownerProperTy').initialValue = chooseVehicle.OWNER_PROPERTY; // 车主性质
      this.formList3.find(item => item.fieldName === 'ownerProperTy').disabled = true;
      this.formList3.find(item => item.fieldName === 'inMileage').initialValue = chooseVehicle.MILEAGE; // 行驶里程
      this.formList3.find(item => item.fieldName === 'inMileage').disabled = true;
      this.formList3.find(item => item.fieldName === 'buyCarDate').initialValue = chooseVehicle.SALES_DATE; // 购车日期
      this.formList3.find(item => item.fieldName === 'buyCarDate').disabled = true;
      this.formList3.find(item => item.fieldName === 'linkAddress').initialValue = chooseVehicle.ADDRESS; // 车主地址
      this.formList3.find(item => item.fieldName === 'linkAddress').disabled = true;
      this.formList3.find(item => item.fieldName === 'engineNo').initialValue = chooseVehicle.ENGINE_NO; // 底盤號
      this.formList3.find(item => item.fieldName === 'engineNo').disabled = true;
      this.showChooseVehicle = false;
    },
    // 删除车辆信息
    delVehicle() {
      this.$refs.formPanel3.RESET_FORM();
      this.formList3.find(item => item.fieldName === 'license').readonly = false;
      this.formList3.find(item => item.fieldName === 'vin').disabled = false;
      this.formList3.find(item => item.fieldName === 'ownerName').disabled = false;
      this.formList3.find(item => item.fieldName === 'ownerProperTy').disabled = false;
      this.formList3.find(item => item.fieldName === 'inMileage').disabled = false;
      this.formList3.find(item => item.fieldName === 'buyCarDate').disabled = false;
      this.formList3.find(item => item.fieldName === 'linkAddress').disabled = false;
      this.formList3.find(item => item.fieldName === 'vehicleModel').disabled = false;
      this.formList3.find(item => item.fieldName === 'engineNo').disabled = false;
    },
    // 关闭弹框
    closeDia() {
      this.showChooseRO = false;
      this.showChooseVehicle = false;
    },
    // 点击结案
    closeComplaint() {
      this.$confirm('是否确认结案?', '提示', {
        confirmButtonText: '是',
        cancelButtonText: '否',
        type: 'warning'
      })
        .then(() => {
          closeComplaintById(this.editComplaintId).then(res => {
            if (res.resultCode == 200) {
              this.isClosed = true;
              // 整个界面置为不可编辑
              this.columns1.map(x => {
                x.disabled = true;
                if (x.title == '操作') {
                  x.hidden = true;
                }
              });
              this.columns1 = [...this.columns1];
              this.formList5.map(x => {
                x.disabled = true;
                if (x.fieldName == 'closeStatus') {
                  x.initialValue = 80421002; // 设为已结案
                }
              });
              this.formList5 = [...this.formList5];
              this.$message.success('结案成功');
              this.$emit('close', false, 'refresh');
            }
          });
        })
        .catch(() => {});
    },
    // 点击提交
    commit() {
      this.$refs.formPanel1.SUBMIT_FORM();
      this.$refs.formPanel2.SUBMIT_FORM();
      this.$refs.formPanel3.SUBMIT_FORM();
      this.$refs.formPanel4.SUBMIT_FORM();
      this.$refs.formPanel5.SUBMIT_FORM();

      // 五个表单都验证成功之后保存
      if (this.form1Over && this.form2Over && this.form3Over && this.form4Over && this.form5Over) {
        // 如果是处理或者结案，先验证处理明细是否填完
        let a = true;
        // if (this.type == 'edit' || this.type == 'close') {
        // if (this.complaintDetailList.length == 0) {
        //   this.$message.error('请添加处理明细');
        //   return;
        // }
        // for (var i = 0; i < this.complaintDetailList.length; i++) {
        //   if (this.complaintDetailList[i].dealer == '' || this.complaintDetailList[i].dealer == null || this.complaintDetailList[i].dealer == undefined) {
        //     this.$message({
        //       type: 'error',
        //       message: '第' + (i + 1) + '行处理人不能为空!'
        //     });
        //     a = false;
        //     break;
        //   }
        //   if (this.complaintDetailList[i].dealResult == '' || this.complaintDetailList[i].dealResult == null || this.complaintDetailList[i].dealResult == undefined) {
        //     this.$message({
        //       type: 'error',
        //       message: '第' + (i + 1) + '行处理结果描述不能为空!'
        //     });
        //     a = false;
        //     break;
        //   }
        // }
        // }
        if (this.type == 'edit') {
          // 处理流程
          if (a) {
            this.customerComplaint.complaintDetailList = this.complaintDetailList;
            this.$confirm('是否完成处理?', '提示', {
              confirmButtonText: '是',
              cancelButtonText: '否',
              type: 'warning'
            })
              .then(() => {
                this.customerComplaint.handleStatus = 80481004; // 完成处理
                this.customerComplaint.complaintEndDate = this.getNowDate(); // 处理完成日期
                this.save();
                this.$emit('close');
              })
              .catch(() => {
                // this.save();
              });
          }
        } else if (this.type == 'close') {
          // 结案流程
          if (a) {
            this.customerComplaint.complaintDetailList = this.complaintDetailList;
            if (
              this.customerComplaint.complaintResult &&
              (this.customerComplaint.complaintResult == 80431001 || this.customerComplaint.complaintResult == 80431002 || this.customerComplaint.complaintResult == 80431003)
            ) {
              this.customerComplaint.isAccept = '1';
            } else {
              this.customerComplaint.isAccept = '0';
            }
            // 如果选择置为重新处理
            if (this.customerComplaint.isRepeat && this.customerComplaint.isRepeat == 1) {
              this.$confirm('是否确认置为重新处理?', '提示', {
                confirmButtonText: '是',
                cancelButtonText: '否',
                type: 'warning'
              })
                .then(() => {
                  this.save();
                  this.$emit('close');
                })
                .catch(() => {
                  this.customerComplaint.isRepeat = 0;
                  this.formList5 = [...this.formList5];
                  // this.save();
                });
            } else {
              this.save();
            }
          }
        } else {
          this.customerComplaint.callId = this.callId; // 弹屏ID
          this.customerComplaint.url = this.ctiUrl;
          this.save();
        }
      }
      this.form1Over = false;
      this.form2Over = false;
      this.form3Over = false;
      this.form4Over = false;
      this.form5Over = false;
    },

    // 点击提交
    report() {
      this.$refs.formPanel1.SUBMIT_FORM();
      this.$refs.formPanel2.SUBMIT_FORM();
      this.$refs.formPanel3.SUBMIT_FORM();
      this.$refs.formPanel4.SUBMIT_FORM();
      this.$refs.formPanel5.SUBMIT_FORM();
      if (!this.customerComplaint.complaintId) {
        this.$message.error('请保存后再进行上传操作');
        return;
      }
      // 五个表单都验证成功之后保存
      if (this.form1Over && this.form2Over && this.form3Over && this.form4Over && this.form5Over) {
        // 如果是处理或者结案，先验证处理明细是否填完
        let a = true;
        // if (this.type == 'edit' || this.type == 'close') {
        //   if (this.complaintDetailList.length == 0) {
        //     this.$message.error('请添加处理明细');
        //     return;
        //   }
        //   for (var i = 0; i < this.complaintDetailList.length; i++) {
        //     if (this.complaintDetailList[i].dealer == '' || this.complaintDetailList[i].dealer == null || this.complaintDetailList[i].dealer == undefined) {
        //       this.$message({
        //         type: 'error',
        //         message: '第' + (i + 1) + '行处理人不能为空!'
        //       });
        //       a = false;
        //       break;
        //     }
        //     if (this.complaintDetailList[i].dealResult == '' || this.complaintDetailList[i].dealResult == null || this.complaintDetailList[i].dealResult == undefined) {
        //       this.$message({
        //         type: 'error',
        //         message: '第' + (i + 1) + '行处理结果描述不能为空!'
        //       });
        //       a = false;
        //       break;
        //     }
        //   }
        // }
        if (this.type == 'edit') {
          // 处理流程
          if (a) {
            this.customerComplaint.complaintDetailList = this.complaintDetailList;
            this.$confirm('是否上报?', '提示', {
              confirmButtonText: '是',
              cancelButtonText: '否',
              type: 'warning'
            })
              .then(() => {
                this.customerComplaint.handleStatus = 80481002; // 完成处理
                this.customerComplaint.complaintEndDate = this.getNowDate(); // 处理完成日期
                this.sendToAcc();
                this.$emit('close');
              })
              .catch(() => {
                this.sendToAcc();
              });
          }
        } else if (this.type == 'close') {
          // 结案流程
          if (a) {
            this.customerComplaint.complaintDetailList = this.complaintDetailList;
            if (
              this.customerComplaint.complaintResult &&
              (this.customerComplaint.complaintResult == 80431001 || this.customerComplaint.complaintResult == 80431002 || this.customerComplaint.complaintResult == 80431003)
            ) {
              this.customerComplaint.isAccept = '1';
            } else {
              this.customerComplaint.isAccept = '0';
            }
            // 如果选择置为重新处理
            if (this.customerComplaint.isRepeat && this.customerComplaint.isRepeat == 1) {
              this.$confirm('是否确认置为重新处理?', '提示', {
                confirmButtonText: '是',
                cancelButtonText: '否',
                type: 'warning'
              })
                .then(() => {
                  // this.sendToAcc();
                  this.$emit('close');
                })
                .catch(() => {
                  this.customerComplaint.isRepeat = 0;
                  this.formList5 = [...this.formList5];
                  this.sendToAcc();
                });
            } else {
              this.sendToAcc();
            }
          }
        } else {
          this.customerComplaint.callId = this.rowData.callId; // 弹屏ID
          this.sendToAcc();
        }
      }
      this.form1Over = false;
      this.form2Over = false;
      this.form3Over = false;
      this.form4Over = false;
      this.form5Over = false;
    },

    // 保存方法
    async save() {
      const [err, data] = await this.$refs.formPanel1.GET_FORM_DATA();
      if (err) return;

      addComplaint(this.customerComplaint).then(res => {
        if (res.resultCode === 200) {
          if (this.type == 'edit') {
            this.getCompalaint();
          } else if (this.type == 'close') {
            this.getCompalaint();
            this.closeing = true; // 置灰保存，点亮结案
          } else {
            this.formList1.find(item => item.fieldName === 'complaintNo').initialValue = res.data.complaintNo;
            this.customerComplaint.complaintId = res.data.complaintId;
            // 赋值版本号
            this.customerComplaint.recordVersion = res.data.recordVersion;
          }
          this.$message.success('保存成功');
          // 保存成功后投诉单号回显
          this.formList1.find(item => item.fieldName === 'complaintNo').initialValue = res.data.complaintNo;
        }
      });
    },

    // 保存方法
    async sendToAcc() {
      sendAccComplaint(this.customerComplaint).then(res => {
        if (res.resultCode === 200) {
          this.$message.success('上报成功');
        }
      });
    },
    // 表单1验证回调
    formChangeHandle1(val) {
      if (!val.complaintNo) {
        val.complaintNo = '';
      }
      Object.assign(this.customerComplaint, val);
      this.form1Over = true;
    },
    // 表单2验证回调
    formChangeHandle2(val) {
      Object.assign(this.customerComplaint, val);
      this.form2Over = true;
    },
    // 表单3验证回调
    formChangeHandle3(val) {
      Object.assign(this.customerComplaint, val);
      this.form3Over = true;
    },
    // 表单4验证回调
    formChangeHandle4(val) {
      Object.assign(this.customerComplaint, val);
      this.form4Over = true;
    },
    // 表单5验证回调
    formChangeHandle5(val) {
      Object.assign(this.customerComplaint, val);
      this.form5Over = true;
    },
    // 点击取消
    cancle() {
      this.$refs.formPanel1.RESET_FORM();
      this.$refs.formPanel2.RESET_FORM();
      this.$refs.formPanel3.RESET_FORM();
      this.$refs.formPanel4.RESET_FORM();
      this.$refs.formPanel5.RESET_FORM();
      this.formList1 = [...this.formList1];
      this.formList2 = [...this.formList2];
      this.formList3 = [...this.formList3];
      this.formList4 = [...this.formList4];
      this.formList5 = [...this.formList5];
      this.customerComplaint.complaintId = '';
      const nowDate = this.getNowDate();
      this.formList1.find(item => item.fieldName === 'complaintDate').initialValue = nowDate;
      this.formList1.find(item => item.fieldName === 'handleStatus').initialValue = 80481001;
    },
    // 子组件时，点退出
    exit() {
      this.$emit('close');
    },
    // 获取全部员工
    async getEmp() {
      const res = await getDealerUser(this.editComplaintId);
      let empList = res.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
      this.formList2.find(item => item.fieldName === 'serviceAdvisor').itemList = empList; // 服务顾问
      this.formList2.find(item => item.fieldName === 'techician').itemList = empList; // 责任技师
      this.formList5.find(item => item.fieldName === 'principal').itemList = empList; // 处理人
      this.columns1.find(item => item.dataIndex === 'dealer').editItems = empList;

      this.formList5.find(item => item.fieldName === 'beComplaintEmp').itemList = empList; // 被投诉人
    },
    async getModelList() {
      const res = await getModelList();
      let modelList = res.data.map(x => ({ text: x.ACC_MODEL_NAME, value: x.ACC_MODEL_CODE + '' }));
      this.formList3.find(item => item.fieldName === 'vehicleModel').itemList = modelList; // 车型
    },
    async getRoInfo(rowData) {
      console.log('getRoInfo===============');
      console.log(rowData);
      // const res = null;
      const type = rowData.visitType;
      if (type === 15721001) {
        /* 售后回访 */
        const queryParams = { roNo: rowData.wtdh };
        const res = await searchRepairOrder(queryParams);
        if (res.resultCode === 200 && res.data.rows.length > 0) {
          const roInfo = res.data.rows[0];
          /* 将车主信息默认带入到投诉人字段中 */
          this.formList1.find(item => item.fieldName === 'complaintName').initialValue = roInfo.DELIVERER; // 投诉人
          this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = roInfo.DELIVERER_MOBILE; // 投诉人手机
          this.formList1.find(item => item.fieldName === 'complaintPhone').initialValue = roInfo.PHONE; // 投诉人电话
          this.formList1.find(item => item.fieldName === 'complaintGender').initialValue = roInfo.GENDER; // 投诉人性别
          /* 带入工单信息 */
          this.formList2.find(item => item.fieldName === 'roNo').initialValue = roInfo.RO_NO; // 工单号
          this.formList2.find(item => item.fieldName === 'roCreateDate').initialValue = roInfo.RO_CREATE_DATE; // 开单时间
          this.formList2.find(item => item.fieldName === 'repairTypeCode').initialValue = roInfo.REPAIR_TYPE_CODE; // 维修类型代码
          this.formList2.find(item => item.fieldName === 'serviceAdvisor').initialValue = roInfo.sa; // 服务顾问
          this.formList2.find(item => item.fieldName === 'deliverer').initialValue = roInfo.DELIVERER; // 送修人
          this.formList2.find(item => item.fieldName === 'delivererPhone').initialValue = roInfo.DELIVERER_PHONE; // 送修人电话
          this.formList2.find(item => item.fieldName === 'delivererMobile').initialValue = roInfo.DELIVERER_MOBILE; // 送修人手机
          this.formList2.find(item => item.fieldName === 'techician').initialValue = roInfo.ct; // 责任技师

          /* 带入车辆数据 */
          this.formList3.find(item => item.fieldName === 'license').initialValue = roInfo.LICENSE; // 车牌号
          this.formList3.find(item => item.fieldName === 'license').readonly = true;
          this.formList3.find(item => item.fieldName === 'vin').initialValue = roInfo.VIN; // VIN
          this.formList3.find(item => item.fieldName === 'vin').disabled = true;
          this.formList3.find(item => item.fieldName === 'ownerName').initialValue = roInfo.OWNER_NAME; // 车主
          this.formList3.find(item => item.fieldName === 'ownerName').disabled = true;
          this.formList3.find(item => item.fieldName === 'ownerProperTy').initialValue = roInfo.OWNER_PROPERTY; // 车主性质
          this.formList3.find(item => item.fieldName === 'ownerProperTy').disabled = true;
          this.formList3.find(item => item.fieldName === 'inMileage').initialValue = roInfo.MILEAGE; // 行驶里程
          this.formList3.find(item => item.fieldName === 'inMileage').disabled = true;
          this.formList3.find(item => item.fieldName === 'buyCarDate').initialValue = roInfo.SALES_DATE; // 购车日期
          this.formList3.find(item => item.fieldName === 'buyCarDate').disabled = true;
          this.formList3.find(item => item.fieldName === 'linkAddress').initialValue = roInfo.ADDRESS; // 车主地址
          this.formList3.find(item => item.fieldName === 'linkAddress').disabled = true;
          this.formList3.find(item => item.fieldName === 'engineNo').initialValue = roInfo.ENGINE_NO; // 车主地址
          this.formList3.find(item => item.fieldName === 'engineNo').disabled = true;
          this.showChooseRO = false;
        } else {
          this.formList1.find(item => item.fieldName === 'complaintName').initialValue = rowData.lxr; // 投诉人
          this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = rowData.lxrsj; // 投诉人手机
          this.formList1.find(item => item.fieldName === 'complaintPhone').initialValue = rowData.lxrsj; // 投诉人电话
        }
      } else if (type === 15721002) {
        /* 销售回访 */
        const queryParams = { vin: rowData.dph };
        const res = await searchVehicle(queryParams);
        if (res.resultCode === 200 && res.data.rows.length > 0) {
          const roInfo = res.data.rows[0];
          /* 将车主信息默认带入到投诉人字段中 */
          this.formList1.find(item => item.fieldName === 'complaintName').initialValue = roInfo.DELIVERER; // 投诉人
          this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = roInfo.DELIVERER_MOBILE; // 投诉人手机
          this.formList1.find(item => item.fieldName === 'complaintPhone').initialValue = roInfo.PHONE; // 投诉人电话
          this.formList1.find(item => item.fieldName === 'complaintGender').initialValue = roInfo.GENDER; // 投诉人性别

          this.formList3.find(item => item.fieldName === 'license').initialValue = roInfo.LICENSE; // 车牌号
          this.formList3.find(item => item.fieldName === 'license').readonly = true;
          this.formList3.find(item => item.fieldName === 'vin').initialValue = roInfo.VIN; // VIN
          this.formList3.find(item => item.fieldName === 'vin').disabled = true;
          this.formList3.find(item => item.fieldName === 'vin').rules = [];
          this.formList3.find(item => item.fieldName === 'ownerName').initialValue = roInfo.OWNER_NAME; // 车主
          this.formList3.find(item => item.fieldName === 'ownerName').disabled = true;
          this.formList3.find(item => item.fieldName === 'ownerProperTy').initialValue = roInfo.OWNER_PROPERTY; // 车主性质
          this.formList3.find(item => item.fieldName === 'ownerProperTy').disabled = true;
          this.formList3.find(item => item.fieldName === 'inMileage').initialValue = roInfo.MILEAGE; // 行驶里程
          this.formList3.find(item => item.fieldName === 'inMileage').disabled = true;
          this.formList3.find(item => item.fieldName === 'buyCarDate').initialValue = roInfo.SALES_DATE; // 购车日期
          this.formList3.find(item => item.fieldName === 'buyCarDate').disabled = true;
          this.formList3.find(item => item.fieldName === 'linkAddress').initialValue = roInfo.ADDRESS; // 车主地址
          this.formList3.find(item => item.fieldName === 'linkAddress').disabled = true;
          this.formList3.find(item => item.fieldName === 'engineNo').initialValue = roInfo.ENGINE_NO; // 底盤號
          this.formList3.find(item => item.fieldName === 'engineNo').disabled = true;
          this.showChooseVehicle = false;
        } else {
          this.formList1.find(item => item.fieldName === 'complaintName').initialValue = rowData.lxr; // 投诉人
          this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = rowData.lxrsj; // 投诉人手机
          this.formList1.find(item => item.fieldName === 'complaintPhone').initialValue = rowData.lxrsj; // 投诉人电话
        }
      } else {
        /* 其他回访 */
        this.formList1.find(item => item.fieldName === 'complaintName').initialValue = rowData.lxr; // 投诉人
        this.formList1.find(item => item.fieldName === 'complaintMobile').initialValue = rowData.lxrsj; // 投诉人手机
        this.formList1.find(item => item.fieldName === 'complaintPhone').initialValue = rowData.lxrsj; // 投诉人电话
      }
    },
    async getDealerOrg() {
      const res = await searchDealerOrg();
      this.formList5.find(item => item.fieldName === 'department').itemList = res.data.map(x => ({ text: x.orgName, value: x.orgId }));
    },
    // 如果有id获取客户投诉详情
    async getCompalaint() {
      console.log('获取客诉单详情');
      const res = await getCompalaintById(this.editComplaintId);
      if (res.resultCode != 200) {
        this.$message.error('查询客户投诉详情失败');
        return;
      }
      if (this.type === 'readDetail') {
        this.formList1.find(x => x.fieldName == 'handleStatus').disabled = true;
      }
      this.customerComplaint = res.data;
      this.complaintDetailList = res.data.complaintDetailList;

      this.formList1.forEach(x => {
        if (x.fieldName != 'receptionst') {
          x.initialValue = this.customerComplaint[x.fieldName];
        }
      });
      this.formList1 = [...this.formList1];
      this.formList2.forEach(x => {
        x.initialValue = this.customerComplaint[x.fieldName];
      });
      this.formList2 = [...this.formList2];
      this.formList3.forEach(x => {
        x.initialValue = this.customerComplaint[x.fieldName];
      });
      this.formList3 = [...this.formList3];
      this.formList4.forEach(x => {
        x.initialValue = this.customerComplaint[x.fieldName];
      });
      this.formList4 = [...this.formList4];
      this.formList5.forEach(x => {
        x.initialValue = this.customerComplaint[x.fieldName];
        if (x.fieldName == 'principal') {
          x.rules = [{ required: true, message: '请填写处理人', trigger: 'blur' }];
        }
        if (x.fieldName === 'priority') {
          if (x.initialValue === 80321002 || x.initialValue === 80321002 || x.initialValue === 80321003 || x.initialValue === 80321004) {
            this.formList5.find(x => x.fieldName === 'userDemand').rules = [{ required: true, message: '请输入客户要求', trigger: 'blur' }];
          } else {
            this.formList5.find(x => x.fieldName === 'userDemand').rules = [];
          }
        }
      });
      this.formList5 = [...this.formList5];

      const defaultUser = this.formList5.find(item => item.fieldName === 'principal').initialValue;
      if (!defaultUser) {
        this.formList5.find(item => item.fieldName === 'principal').initialValue = getUser();
      }
      this.complaintDetailList = [...this.complaintDetailList];
      if (this.formList1.find(item => item.fieldName === 'complaintKind').initialValue !== 82131001) {
        /* 查看明细页面去除必填项 */
        this.formList4.find(item => item.fieldName === 'complaintSummary').rules = null;
        this.formList4.find(item => item.fieldName === 'complaintReason').rules = null;
        this.formList4.find(item => item.fieldName === 'surveyContent').rules = null;
        this.formList4.find(item => item.fieldName === 'resolvent').rules = null;
        this.formList4.find(item => item.fieldName === 'asdtxt').rules = null;
        /* 查看明细页面去除必填项 */
        this.formList5.find(item => item.fieldName === 'priority').rules = null;
        this.formList5.find(item => item.fieldName === 'complaintOrigin').rules = null;
        this.formList5.find(item => item.fieldName === 'result').rules = null;
      }
    },
    // 校验手机
    checkPhone(rule, value, callback) {
      if (!value) {
        return callback(new Error(rule.message));
      } else {
        const reg = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
        if (reg.test(value)) {
          callback();
        } else {
          return callback(new Error(rule.message));
        }
      }
      callback();
    },
    setDefaultDic() {
      if (this.type === 'create') {
        this.formList1.find(x => x.fieldName == 'handleStatus').initialValue = 80481001;
      }
      if (this.type !== 'create') {
        let it = this.createDictList('8217');
        let it1 = this.createDictList('8216');
        this.formList1.find(x => x.fieldName == 'complaintMainType').itemList = this.createDictList('8209');
        for (let i = 0; i < it1.length; i++) {
          this.formList1.find(x => x.fieldName == 'complaintMainType').itemList.push(it1[i]);
        }
        this.formList1.find(x => x.fieldName == 'complaintSubType').itemList = this.createDictList('8210');
        for (let i = 0; i < it.length; i++) {
          this.formList1.find(x => x.fieldName == 'complaintSubType').itemList.push(it[i]);
        }
      }
    },
    changeComplaintRules(val) {
      if (val !== 82131001) {
        this.formList5.find(item => item.fieldName === 'priority').rules = null;
        this.formList5.find(item => item.fieldName === 'complaintOrigin').rules = null;
        this.formList5.find(item => item.fieldName === 'result').rules = null;
      } else {
        this.formList5.find(item => item.fieldName === 'priority').rules = [{ required: true, message: '请选择投诉级别', trigger: 'change' }];
        this.formList5.find(item => item.fieldName === 'complaintOrigin').rules = [{ required: true, message: '投诉来源', trigger: 'change' }];
        this.formList5.find(item => item.fieldName === 'result').rules = [{ required: true, message: '投诉结果', trigger: 'change' }];
      }
    },
    changeComplaintMainType(val) {
      this.formList1.find(x => x.fieldName == 'complaintMainType').initialValue = '';
      this.formList1.find(x => x.fieldName == 'complaintMainType').itemList = [];
      this.formList1.find(x => x.fieldName == 'complaintSubType').initialValue = '';
      this.formList1.find(x => x.fieldName == 'complaintSubType').itemList = [];
      if (val === 82151001) {
        /* 服务 */
        this.complaintMainTypeList = [{ text: '服务类', value: 82161001 }];
        this.formList1.find(x => x.fieldName == 'complaintMainType').itemList = this.complaintMainTypeList;
      } else if (val === 82151002) {
        /* 技术 */
        this.complaintMainTypeList = [{ text: '技术类', value: 82161002 }];
        this.formList1.find(x => x.fieldName == 'complaintMainType').itemList = this.complaintMainTypeList;
      } else if (val === 82151003) {
        /* 销售 */
        this.complaintMainTypeList = [{ text: '销售类', value: 82161003 }];
        this.formList1.find(x => x.fieldName == 'complaintMainType').itemList = this.complaintMainTypeList;
      } else if (val === 82151004) {
        /* 一汽-大众金融服务政策 */
        this.complaintMainTypeList = [{ text: '金融类', value: 82161004 }];
        this.formList1.find(x => x.fieldName == 'complaintMainType').itemList = this.complaintMainTypeList;
      } else if (val === 82151005) {
        /* 备件类 */
        this.complaintMainTypeList = [{ text: '备件类', value: 82161005 }];
        this.formList1.find(x => x.fieldName == 'complaintMainType').itemList = this.complaintMainTypeList;
      }
    },
    changeComplaintSubType(val) {
      this.formList1.find(x => x.fieldName == 'complaintSubType').initialValue = '';
      this.formList1.find(x => x.fieldName == 'complaintSubType').itemList = [];
      if (val === 82161001) {
        /* 服务类 */
        this.complaintSubTypeList = [
          { text: 'T投诉-经销商-服务水平', value: 82171001 },
          { text: 'T投诉-经销商-服务规范', value: 82171002 },
          { text: 'T投诉-经销商-工时费用', value: 82171003 },
          { text: 'T投诉-经销商-服务替换车', value: 82171004 },
          { text: 'T投诉-经销商-紧急救援', value: 82171005 },
          { text: 'T投诉-经销商-机动性保障', value: 82171006 },
          { text: 'T投诉-经销商-备件周期', value: 82171007 },
          { text: 'T投诉-经销商-备件质量', value: 82171008 },
          { text: 'T投诉-经销商-备件价格', value: 82171009 },
          { text: 'T投诉-经销商-精品附件', value: 82171010 },
          { text: 'T投诉-车辆-随车文件(说明书/手册）', value: 82171011 },
          { text: 'T投诉-一汽-大众服务活动', value: 82171012 },
          { text: 'T投诉-一汽-大众其他', value: 82171013 },
          { text: 'T投诉-奥迪股份公司AUDI', value: 82171014 },
          { text: '紧急救援', value: 82171015 },
          { text: '服务替换车', value: 82171016 },
          { text: '服务费用', value: 82171017 },
          { text: '服务用户对待', value: 82171018 },
          { text: '服务流程', value: 82171019 },
          { text: '服务优惠活动', value: 82171020 },
          { text: '精品附件', value: 82171021 },
          { text: '二手车问题', value: 82171022 }
        ];
      } else if (val === 82161002) {
        /* 技术类 */
        this.complaintSubTypeList = [
          { text: 'T投诉-经销商-车间维修工作', value: 82171023 },
          { text: 'T投诉-车辆-非重大安全类产品质量故障', value: 82171024 },
          { text: 'T投诉-经销商-索赔', value: 82171025 },
          { text: 'T投诉-经销商-优惠索赔', value: 82171026 },
          { text: 'T投诉-车辆-RC/气襄/安全带/事故车', value: 82171027 },
          { text: '车间维修工作', value: 82171028 },
          { text: '非重大产品质量问题', value: 82171029 },
          { text: '重大产品质量问题', value: 82171030 }
        ];
      } else if (val === 82161003) {
        /* 销售类 */
        this.complaintSubTypeList = [
          { text: 'T投诉-经销商-销售业务规范', value: 82171031 },
          { text: 'T投诉-经销商-销售订车周期', value: 82171032 },
          { text: 'T投诉-经销商-车辆订购/交付', value: 82171033 },
          { text: 'T投诉-经销商-销售费用', value: 82171034 },
          { text: 'T投诉-经销商-销售用户对待', value: 82171035 },
          { text: 'T投诉-经销商-销售随车文件', value: 82171036 },
          { text: 'T投诉-一汽-大众二手车及大用户销售', value: 82171037 },
          { text: 'T投诉-一汽-大众金融服务政策', value: 82171038 },
          { text: '销售用户对待', value: 82171039 },
          { text: '销售流程', value: 82171040 },
          { text: '销售费用', value: 82171041 },
          { text: '销售优惠活动', value: 82171042 },
          { text: '直销车大用户问题', value: 82171043 }
        ];
      } else if (val === 82161004) {
        /* 金融类 */
        this.complaintSubTypeList = [{ text: '一汽-大众金融服务政策', value: 82171044 }];
      } else if (val === 82161005) {
        /* 备件类 */
        this.complaintSubTypeList = [
          { text: '备件周期', value: 82171045 },
          { text: '备件质量', value: 82171046 },
          { text: '备件价格', value: 82171047 }
        ];
      }
      this.formList1.find(x => x.fieldName == 'complaintSubType').itemList = this.complaintSubTypeList;
    },
    // 呼出系统
    exhale(a) {
      let phone = a + this.formList1.find(item => item.fieldName === 'complaintPhone').initialValue; // 投诉电话
      let ownerName = a + this.formList1.find(item => item.fieldName === 'complaintName').initialValue; // 投诉电话
      let ownerCode = '111';
      let userData = {
        userData: {
          // RO_NO: val.RO_NO,
          OWNER_CODE: ownerCode,
          OWNER_NAME: ownerName,
          date: moment().format('YYYY-MM-DD hh:MM:SS')
        }
      };
      if (CallCenter.isLogin()) {
        CallCenter.callout(phone, null, null, null, null, userData);
        // this.roNo = val.RO_NO;
      } else {
        this.$notify.warning({ title: '提示信息', message: '没有外呼权限!' });
      }
    },
    after() {
      let that = this;
      CallCenter.addEventListener('after', function(json) {
        console.log('验证是否监听到了after方法=============================>true');
        console.log('返回值================================>begin');
        console.log('返回值录音第一段================================>', json.recordDownloadUrl);
        console.log('返回值录音第二段================================>', json.mediano);
        console.log('返回值录音第三段================================>', json.filename);
        let url = json.recordDownloadUrl + '/' + json.mediano + '?file=' + json.filename;
        console.log('返回值录音路径================================>', url);
        let getCallId = json.callid;
        console.log('返回值CALLID================================>', getCallId);
        that.ctiUrl = url;
        console.log('返回URL值录音后台传递================================>', that.ctiUrl);
        that.callid = getCallId;
        console.log('返回CALLID值录音后台传递================================>', that.callid);
      });
    }
  }
};
</script>
<style lang="less" scoped>
.box {
  border: 1px solid @borderColor;
  border-radius: @borderRadius;
  box-shadow: @boxShadow;
  padding: @modulePadding;
  margin-top: 20px;
}
.hr1 {
  border: 0;
  height: 1px;
  background-color: @borderColor;
}
</style>
